package com.easy;

import java.util.Arrays;

/**
 * Created by Lxk on 2019/6/10.
 */
public class Solution1051 {

    public int heightChecker(int[] heights) {
        if(heights==null || heights.length==0){
            return 0;
        }
        int[] copyHeights = Arrays.copyOf(heights,heights.length);

        for(int i = copyHeights.length-1;i >= 0 ; i--){
            for(int k = 0;k < i;k++){
                if(copyHeights[k] > copyHeights[k+1]){
                    int temp = copyHeights[k];
                    copyHeights[k] = copyHeights[k+1];
                    copyHeights[k+1] = temp;
                }
            }
        }

        int count = 0;
        for(int i = 0;i < heights.length; i++){
            if(heights[i]!=copyHeights[i]){
                count++;
            }
        }
        return count;
    }

}
